	<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sj" tagdir="/WEB-INF/tags/spring-jquery-tags"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<link rel="stylesheet" type="text/css" media="screen"
	href="<c:url value='/css/website.css' />" />
<script type="text/javascript"
	src="<c:url value='/js/jquery/jquery.numeric.js'/>"></script>
<script type="text/javascript"
	src="<c:url value='/js/jquery/jquery.formatCurrency-1.4.0.pack.js'/>"></script>
<script type="text/javascript"
	src="<c:url value='/js/jquery/jquery.tinyscrollbar.min.js'/>"></script>
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						$('#pageTitle')
								.text(
										'<spring:message code="editKnowledgeManagement.heading" />');
						$.validator.addMethod("themeValidation", function(
								value, element) {
							var total = Number($('#themebusassocdev').val()) + Number($('#themelegalregreform').val()) + Number($('#themewomenyouth').val())+ Number($('#themeaccesstoinfo').val())+ Number($('#themeinformalsectorproperty').val())+ Number($('#themecorruption').val())+ Number($('#themecorporategovernance').val())+ Number($('#themedemocraticgovernance').val());
							//var val = value;
							if(($('#themebusassocdev').val().length == 0)  &&  ($('#themelegalregreform').val().length == 0)  &&  ($('#themewomenyouth').val().length == 0)&&  ($('#themeaccesstoinfo').val().length == 0)&&  ($('#themeinformalsectorproperty').val().length == 0)&&  ($('#themecorruption').val().length == 0)&&  ($('#themecorporategovernance').val().length == 0)&&  ($('#themedemocraticgovernance').val().length == 0)){
								return true;
							}
							if (total != 100) {
									return false;
							}
							return true;
						}, "The total % between the 'Project Themes' MUST equal exactly 100%!");
						$.validator.addMethod("lowValidation", function(
								value, element) {
							var total = Number($('#lowpartnership').val()) + Number($('#lowproorgdevelopment').val()) + Number($('#lowcipeadvocacy').val());
							//var val = value;
							if(($('#lowpartnership').val().length == 0) && ($('#lowproorgdevelopment').val().length == 0) && ($('#lowcipeadvocacy').val().length == 0)){
								return true;
							}
							if (total != 100) {
									return false;
							}
							return true;
						}, "The total % between the 'Lines of Work' MUST equal exactly 100%!");
						$("#editKnowledgeManagementForm").validate({
							rules : {
								/*themebusassocdev : {
									themeLOWValidation : true
								},
								themelegalregreform : {
									themeLOWValidation : true
								},
								themewomenyouth : {
									themeLOWValidation : true
								},
								themeaccesstoinfo : {
									themeLOWValidation : true
								},
								themeinformalsectorproperty : {
									themeLOWValidation : true
								},
								themecorruption : {
									themeLOWValidation : true
								},
								themecorporategovernance : {
									themeLOWValidation : true
								},
								*/
								themedemocraticgovernance : {
									themeValidation : true
								},
								lowcipeadvocacy : {
									lowValidation : true
								}
							}
						});

						$('#themebusassocdev').numeric();
						$('#themelegalregreform').numeric();
						$('#themewomenyouth').numeric();
						$('#themeaccesstoinfo').numeric();
						$('#themeinformalsectorproperty').numeric();
						$('#themecorruption').numeric();
						$('#themecorporategovernance').numeric();
						$('#themedemocraticgovernance').numeric();
						
						$('#lowpartnership').numeric();
						$('#lowproorgdevelopment').numeric();
						$('#lowcipeadvocacy').numeric();
						
						$('#editButton').click(function() {
							loadDiv('content', 'showEditKnowledgeManagement.do?editable=true&id=' + $(this).attr('cipeprojectId'));
						});

						$('#cancelButton')
						.click(
								function() {
									var ans = confirm('Are you sure you want to cancel editing this record without saving it?');
									if (ans) {
										loadDiv('content', 'showEditKnowledgeManagement.do?editable=false&id=' + $(this).attr('cipeprojectId'));
									}
								});

						countChecked();
						$(":checkbox").click(countChecked);

						enableDisabledControls();
						
						$('#scrollbar1').tinyscrollbar();	
					});

	function countChecked() {
	  var n = $("input:checked").length;
	  //$("input:checked").each(function(i){
		//})
	}
	
	function enableDisabledControls() {
		<c:if test="${cipeproject.id !=null and cipeproject.id gt 0}">
		 <c:choose>
		  <c:when test="${param.editable=='true'}">
		 	$("#acronym").attr("readonly", "readonly");
			$("#projectID").attr("readonly", "readonly");
			$("#projectTitle").attr("readonly", "readonly");
			$("#projectStartDate").attr("readonly", "readonly");
			$("#projectEndDate").attr("readonly", "readonly");
			$("#managementFunds").attr("readonly","readonly");

			$("#partnerId").attr("disabled", "disabled");
			$("#cipeprojecttypeId").attr("disabled", "disabled");
			$("#programOfficerId").attr("disabled", "disabled");
			$("#cipeprojectstatusId").attr("disabled", "disabled");
			$("#regionId").attr("disabled", "disabled");
			$("#countryId").attr("disabled", "disabled");
			
			$("input[type^='button']").removeAttr("disabled","disabled");
			$("input[type^='submit']").removeAttr("disabled","disabled");
			$("#editButton").attr("disabled","disabled");
			//$("#mail-to-trigger").removeAttr("disabled","disabled");
		  </c:when>
		  <c:otherwise>
			$("form :input").attr("disabled","disabled");
			$("input[type^='button']").removeAttr("disabled","disabled");
			$("input[type^='submit']").removeAttr("disabled","disabled");
			$("#loginFormSubmit").attr("disabled","disabled");
			$("#cancelButton").attr("disabled","disabled");
			$("#editButton").removeAttr("disabled","disabled");
			//$("#mail-to-trigger").attr("disabled","disabled");
		  </c:otherwise>
		 </c:choose>
		</c:if>
	}
	
	$(function() {
		var value = $("#projectStartDate").attr("readonly");
		if (value == null) {
			$("#projectStartDate").datepicker();
		}
	});

	$(function() {
		var value = $("#projectEndDate").attr("readonly");
		if (value == null) {
			$("#projectEndDate").datepicker();
		}
	});

	$('#edit-projectkeyword-link').click(
			function() {
				loadDiv('content', 'showEditKeyword.do?id='
						+ $(this).attr('projectkeywordId'));
			});
	$('#view-cipeprojectsummary').click(
			function() {
				loadDiv('content', 'showCipeprojectSummary.do?id='
						+ $(this).attr('cipeprojectId'));
			});
	$('#mail-to-trigger')
			.click(
					function() {
						window.location = 'mailto:knowledgemanagement@cipe.org?Subject=Request%20a%20new%20\'Keyword\'%20be%20added%20to%20the%20list%20of%20Knowledge%20Management%20keywords';
					});
	$('.close-button').click(function() {
		if (confirm('Are you sure you want to close the form?')) {
			window.location = '../secure/showDashboard.do';
		}
	});
</script>
<div id="editKnowledgeManagementDiv"><form:form
	name="editKnowledgeManagementForm" id="editKnowledgeManagementForm"
	action="saveKnowledgeManagement.do" method="post"
	modelAttribute="cipeproject">
	<form:hidden path="id" />
	<c:choose>
		<c:when test="${param.editable=='true'}">
			<input type="hidden" name="editable" value="true" />
		</c:when>
		<c:otherwise>
			<input type="hidden" name="editable" value="false" />
		</c:otherwise>
	</c:choose>
	<table>
		<tr class="row">
			<td colspan="2" valign="top"><input type="button"
				id="view-cipeprojectsummary"
				value="<spring:message code="editKnowledgeManagement.link.viewProjectGrant" />"
				cipeprojectId="${cipeproject.id}" /></td>
			<td valign="top"><input type="button" class="close-button"
				value="Close Form" />&nbsp;</td>
		</tr>
		<%--
			<tr class="row">
				<td colspan="2" align="center" class="menu-heading"><spring:message code="editKnowledgeManagement.heading" /></td>
				<td><input type="button" id="view-cipeprojectsummary" value="<spring:message code="editKnowledgeManagement.link.viewProjectGrant" />" cipeprojectId="${cipeproject.id}" />&nbsp;<input type="button" class="close-button" value="Close Form">&nbsp;</td>
			</tr>
			 --%>
		<tr class="row">
			<td class="label">&nbsp;</td>
			<td class="input-field" colspan="2"><%@ include
				file="/common/messages.jsp"%></td>
		</tr>
		<tr class="row">
			<td class="label">&nbsp;</td>
			<td class="input-field" colspan="2"><spring:message
				code="editKnowledgeManagement.heading.project" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.partner" /></td>
			<td class="input-field"><form:select id="partnerId"
				path="partner.id" cssClass="input-full-width">
				<form:options items="${partnerList}" itemValue="id"
					itemLabel="partnerName" />
			</form:select></td>
			<td><form:errors path="partner.id" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.acronym" /></td>
			<td class="input-field"><form:input path="acronym"
				cssClass="input-full-width text_grey" /></td>
			<td><form:errors path="acronym" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.type" /></td>
			<td class="input-field"><form:select id="cipeprojecttypeId"
				path="cipeprojecttype.id" cssClass="input-full-width">
				<form:options items="${cipeprojecttypeList}" itemValue="id"
					itemLabel="displayName" />
			</form:select></td>
			<td><form:errors path="cipeprojecttype.id" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.projectID" /></td>
			<td class="input-field"><form:input path="projectID"
				cssClass="input-full-width" /></td>
			<td><form:errors path="projectID" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.projectTitle" /></td>
			<td class="input-field"><form:input path="projectTitle"
				cssClass="input-full-width" /></td>
			<td><form:errors path="projectTitle" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.startDate" /></td>
			<td class="input-field"><form:input path="projectStartDate"
				cssClass="input-full-width" /></td>
			<td><form:errors path="projectStartDate" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.endDate" /></td>
			<td class="input-field"><form:input path="projectEndDate"
				cssClass="input-full-width" /></td>
			<td><form:errors path="projectEndDate" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.programOfficer" /></td>
			<td class="input-field"><form:select id="programOfficerId"
				path="programOfficer.id" cssClass="input-full-width">
				<form:options items="${programOfficerList}" itemValue="id"
					itemLabel="fullName" />
			</form:select></td>
			<td><form:errors path="programOfficer.id" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.status" /></td>
			<td class="input-field"><form:select id="cipeprojectstatusId"
				path="cipeprojectstatus.id" cssClass="input-full-width">
				<form:options items="${cipeprojectstatusList}" itemValue="id"
					itemLabel="displayName" />
			</form:select></td>
			<td><form:errors path="cipeprojecttype.id" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.region" /></td>
			<td class="input-field"><form:select id="regionId"
				path="region.id" cssClass="input-full-width">
				<form:options items="${regionList}" itemValue="id"
					itemLabel="displayName" />
			</form:select></td>
			<td><form:errors path="region.id" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.country" /></td>
			<td class="input-field"><form:select id="countryId"
				path="country.id" cssClass="input-full-width">
				<form:options items="${countryList}" itemValue="id"
					itemLabel="displayName" />
			</form:select></td>
			<td><form:errors path="country.id" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.managementFunds" /></td>
			<td class="input-field"><form:input path="managementFunds"
				cssClass="input-full-width" /></td>
			<td><form:errors path="managementFunds" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="input-field" colspan="3">
			<table>
				<tr>
					<td class="label">&nbsp;</td>
					<td class="input-field" colspan="2"><spring:message
						code="editKnowledgeManagement.heading.information" /></td>
					<td class="label">&nbsp;</td>
					<td class="input-field" colspan="2"><spring:message
						code="editKnowledgeManagement.heading.evaluation" /></td>
				</tr>
				<tr>
					<td class="label"><spring:message
						code="editKnowledgeManagement.label.organizationtype" /></td>
					<td class="input-field"><form:select id="organizationtypeId"
						path="organizationtype.id" cssClass="input-full-width">
						<form:option value="" label="Select" />
						<form:options items="${organizationtypeList}" itemValue="id"
							itemLabel="displayName" />
					</form:select></td>
					<td><form:errors path="organizationtype.id" cssClass="error" /></td>
					<td class="label"><spring:message
						code="editKnowledgeManagement.label.impact" /></td>
					<td class="input-field"><form:select path="projectimpact"
						cssClass="input-full-width">
						<form:option value="" label="Select" />
						<form:option value="High" label="High" />
						<form:option value="Medium" label="Medium" />
						<form:option value="Low" label="Low" />
					</form:select></td>
					<td><form:errors path="projectimpact" cssClass="error" /></td>
				</tr>
			</table>
			</td>
		</tr>
		<tr class="row">
			<td class="label">&nbsp;</td>
			<td class="input-field" colspan="2"><spring:message
				code="editKnowledgeManagement.heading.themes" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.business" /></td>
			<td class="input-field"><form:input path="themebusassocdev"
				cssClass="input-full-width" /> <spring:message code="label.percent"></spring:message></td>
			<td><form:errors path="themebusassocdev" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.legal" /></td>
			<td class="input-field"><form:input path="themelegalregreform"
				cssClass="input-full-width" /> <spring:message code="label.percent"></spring:message></td>
			<td><form:errors path="themelegalregreform" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.women" /></td>
			<td class="input-field"><form:input path="themewomenyouth"
				cssClass="input-full-width" /> <spring:message code="label.percent"></spring:message></td>
			<td><form:errors path="themewomenyouth" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.access" /></td>
			<td class="input-field"><form:input path="themeaccesstoinfo"
				cssClass="input-full-width" /> <spring:message code="label.percent"></spring:message></td>
			<td><form:errors path="themeaccesstoinfo" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.informal" /></td>
			<td class="input-field"><form:input
				path="themeinformalsectorproperty" cssClass="input-full-width" /> <spring:message
				code="label.percent"></spring:message></td>
			<td><form:errors path="themeinformalsectorproperty"
				cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.corruption" /></td>
			<td class="input-field"><form:input path="themecorruption"
				cssClass="input-full-width" /> <spring:message code="label.percent"></spring:message></td>
			<td><form:errors path="themecorruption" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.corporate" /></td>
			<td class="input-field"><form:input
				path="themecorporategovernance" cssClass="input-full-width" /> <spring:message
				code="label.percent"></spring:message></td>
			<td><form:errors path="themecorporategovernance"
				cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.democratic" /></td>
			<td class="input-field"><form:input
				path="themedemocraticgovernance" cssClass="input-full-width" /> <spring:message
				code="label.percent"></spring:message></td>
			<td><form:errors path="themedemocraticgovernance"
				cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label">&nbsp;</td>
			<td class="input-field" colspan="2"><spring:message
				code="editKnowledgeManagement.heading.lines" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.partnership" /></td>
			<td class="input-field"><form:input path="lowpartnership"
				cssClass="input-full-width" /> <spring:message code="label.percent"></spring:message></td>
			<td><form:errors path="lowpartnership" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.development" /></td>
			<td class="input-field"><form:input path="lowproorgdevelopment"
				cssClass="input-full-width" /> <spring:message code="label.percent"></spring:message></td>
			<td><form:errors path="lowproorgdevelopment" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label"><spring:message
				code="editKnowledgeManagement.label.advocacy" /></td>
			<td class="input-field"><form:input path="lowcipeadvocacy"
				cssClass="input-full-width" /> <spring:message code="label.percent"></spring:message></td>
			<td><form:errors path="lowcipeadvocacy" cssClass="error" /></td>
		</tr>
		<tr class="row">
			<td class="label">&nbsp;</td>
			<td class="input-field" colspan="2"><spring:message
				code="editKnowledgeManagement.heading.keyword" /></td>
		</tr>
		<tr class="row">
			<td class="tablesorter" colspan="3">
			<div id="scrollbar1">
			<div class="scrollbar">
			<div class="track">
			<div class="thumb">
			<div class="end"></div>
			</div>
			</div>
			</div>
			<div class="viewport">
			<div class="overview">
			<table>
				<thead>
					<tr>
						<th><spring:message
							code="knowledgeManagementlist.table.heading.keyword" /></th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td><form:checkboxes items="${keywordList}" path="selectedKeywords"
							itemValue="id" itemLabel="displayName"
							cssClass="input-full-width text_white" /> <form:errors
							path="keywords" cssClass="error" /></td>
					</tr>
				</tbody>
			</table>
			</div>
			</div>
			</div>
			<input type="button" id="mail-to-trigger"
				value="<spring:message code="editKnowledgeManagement.link.suggest" />" /></td>
		</tr>
		<tr class="row">
			<td class="label">&nbsp;</td>
			<td><input id="editButton" type="button"
				value="<spring:message code='button.edit' />"
				cipeprojectId="${cipeproject.id}" /> <input id="cancelButton"
				type="button" value="<spring:message code='button.cancelEdit' />"
				cipeprojectId="${cipeproject.id}" /> <sj:submit
				id="loginFormSubmit" target="editKnowledgeManagementDiv"
				key="button.save" validate="true" /></td>
			<td>&nbsp;</td>
		</tr>
	</table>
</form:form></div>